home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / ADB / ModifyMouseAccl / CursorDevices.Glue.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  10.1 KB  |  318 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CursorDevices.Glue.c
  3.     
  4.     Description:
  5.  
  6.     Author:        
  7.  
  8.     Copyright:     Copyright: © 1984-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.  
  21. */
  22. #include <MixedMode.h>
  23. #include <CursorDevices.h>
  24. #include <Patches.h>
  25.  
  26. #define RESULT_OFFSET(type) ((sizeof(type) == 1) ? 3 : ((sizeof(type) == 2) ? 1 : 0))
  27.  
  28.  
  29. pascal OSErr CursorDeviceMove(CursorDevicePtr ourDevice, long deltaX, long deltaY)
  30. {
  31.     #ifdef applec
  32.         #if sizeof(OSErr) > 4
  33.             #error "Result types larger than 4 bytes are not supported."
  34.         #endif
  35.     #endif
  36.     long    private_result;
  37.  
  38.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  39.         kD0DispatchedPascalStackBased
  40.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  41.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  42.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  43.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(deltaX)))
  44.          | DISPATCHED_STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(deltaY))),
  45.         0x00000000,
  46.         ourDevice,
  47.         deltaX,
  48.         deltaY);
  49.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  50. }
  51.  
  52. pascal OSErr CursorDeviceMoveTo(CursorDevicePtr ourDevice, long absX, long absY)
  53. {
  54.     #ifdef applec
  55.         #if sizeof(OSErr) > 4
  56.             #error "Result types larger than 4 bytes are not supported."
  57.         #endif
  58.     #endif
  59.     long    private_result;
  60.  
  61.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  62.         kD0DispatchedPascalStackBased
  63.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  64.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  65.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  66.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(absX)))
  67.          | DISPATCHED_STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(absY))),
  68.         0x00000001,
  69.         ourDevice,
  70.         absX,
  71.         absY);
  72.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  73. }
  74.  
  75. pascal OSErr CursorDeviceFlush(CursorDevicePtr ourDevice)
  76. {
  77.     #ifdef applec
  78.         #if sizeof(OSErr) > 4
  79.             #error "Result types larger than 4 bytes are not supported."
  80.         #endif
  81.     #endif
  82.     long    private_result;
  83.  
  84.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  85.         kD0DispatchedPascalStackBased
  86.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  87.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  88.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  89.         0x00000002,
  90.         ourDevice);
  91.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  92. }
  93.  
  94. pascal OSErr CursorDeviceButtons(CursorDevicePtr ourDevice, short buttons)
  95. {
  96.     #ifdef applec
  97.         #if sizeof(OSErr) > 4
  98.             #error "Result types larger than 4 bytes are not supported."
  99.         #endif
  100.     #endif
  101.     long    private_result;
  102.  
  103.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  104.         kD0DispatchedPascalStackBased
  105.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  106.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  107.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  108.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(buttons))),
  109.         0x00000003,
  110.         ourDevice,
  111.         buttons);
  112.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  113. }
  114.  
  115. pascal OSErr CursorDeviceButtonDown(CursorDevicePtr ourDevice)
  116. {
  117.     #ifdef applec
  118.         #if sizeof(OSErr) > 4
  119.             #error "Result types larger than 4 bytes are not supported."
  120.         #endif
  121.     #endif
  122.     long    private_result;
  123.  
  124.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  125.         kD0DispatchedPascalStackBased
  126.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  127.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  128.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  129.         0x00000004,
  130.         ourDevice);
  131.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  132. }
  133.  
  134. pascal OSErr CursorDeviceButtonUp(CursorDevicePtr ourDevice)
  135. {
  136.     #ifdef applec
  137.         #if sizeof(OSErr) > 4
  138.             #error "Result types larger than 4 bytes are not supported."
  139.         #endif
  140.     #endif
  141.     long    private_result;
  142.  
  143.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  144.         kD0DispatchedPascalStackBased
  145.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  146.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  147.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  148.         0x00000005,
  149.         ourDevice);
  150.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  151. }
  152.  
  153. pascal OSErr CursorDeviceButtonOp(CursorDevicePtr ourDevice, short buttonNumber, ButtonOpcode opcode, long data)
  154. {
  155.     #ifdef applec
  156.         #if sizeof(OSErr) > 4
  157.             #error "Result types larger than 4 bytes are not supported."
  158.         #endif
  159.     #endif
  160.     long    private_result;
  161.  
  162.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  163.         kD0DispatchedPascalStackBased
  164.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  165.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  166.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  167.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(buttonNumber)))
  168.          | DISPATCHED_STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(opcode)))
  169.          | DISPATCHED_STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(data))),
  170.         0x00000006,
  171.         ourDevice,
  172.         buttonNumber,
  173.         opcode,
  174.         data);
  175.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  176. }
  177.  
  178. pascal OSErr CursorDeviceSetButtons(CursorDevicePtr ourDevice, short numberOfButtons)
  179. {
  180.     #ifdef applec
  181.         #if sizeof(OSErr) > 4
  182.             #error "Result types larger than 4 bytes are not supported."
  183.         #endif
  184.     #endif
  185.     long    private_result;
  186.  
  187.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  188.         kD0DispatchedPascalStackBased
  189.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  190.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  191.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  192.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(numberOfButtons))),
  193.         0x00000007,
  194.         ourDevice,
  195.         numberOfButtons);
  196.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  197. }
  198.  
  199. pascal OSErr CursorDeviceSetAcceleration(CursorDevicePtr ourDevice, Fixed acceleration)
  200. {
  201.     #ifdef applec
  202.         #if sizeof(OSErr) > 4
  203.             #error "Result types larger than 4 bytes are not supported."
  204.         #endif
  205.     #endif
  206.     long    private_result;
  207.  
  208.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  209.         kD0DispatchedPascalStackBased
  210.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  211.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  212.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  213.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(acceleration))),
  214.         0x00000008,
  215.         ourDevice,
  216.         acceleration);
  217.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  218. }
  219.  
  220. pascal OSErr CursorDeviceDoubleTime(CursorDevicePtr ourDevice, long durationTicks)
  221. {
  222.     #ifdef applec
  223.         #if sizeof(OSErr) > 4
  224.             #error "Result types larger than 4 bytes are not supported."
  225.         #endif
  226.     #endif
  227.     long    private_result;
  228.  
  229.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  230.         kD0DispatchedPascalStackBased
  231.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  232.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  233.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  234.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(durationTicks))),
  235.         0x00000009,
  236.         ourDevice,
  237.         durationTicks);
  238.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  239. }
  240.  
  241. pascal OSErr CursorDeviceUnitsPerInch(CursorDevicePtr ourDevice, Fixed resolution)
  242. {
  243.     #ifdef applec
  244.         #if sizeof(OSErr) > 4
  245.             #error "Result types larger than 4 bytes are not supported."
  246.         #endif
  247.     #endif
  248.     long    private_result;
  249.  
  250.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  251.         kD0DispatchedPascalStackBased
  252.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  253.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  254.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice)))
  255.          | DISPATCHED_STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(resolution))),
  256.         0x0000000A,
  257.         ourDevice,
  258.         resolution);
  259.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  260. }
  261.  
  262. pascal OSErr CursorDeviceNextDevice(CursorDevicePtr *ourDevice)
  263. {
  264.     #ifdef applec
  265.         #if sizeof(OSErr) > 4
  266.             #error "Result types larger than 4 bytes are not supported."
  267.         #endif
  268.     #endif
  269.     long    private_result;
  270.  
  271.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  272.         kD0DispatchedPascalStackBased
  273.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  274.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  275.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  276.         0x0000000B,
  277.         ourDevice);
  278.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  279. }
  280.  
  281. pascal OSErr CursorDeviceNewDevice(CursorDevicePtr *ourDevice)
  282. {
  283.     #ifdef applec
  284.         #if sizeof(OSErr) > 4
  285.             #error "Result types larger than 4 bytes are not supported."
  286.         #endif
  287.     #endif
  288.     long    private_result;
  289.  
  290.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  291.         kD0DispatchedPascalStackBased
  292.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  293.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  294.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  295.         0x0000000C,
  296.         ourDevice);
  297.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  298. }
  299.  
  300. pascal OSErr CursorDeviceDisposeDevice(CursorDevicePtr ourDevice)
  301. {
  302.     #ifdef applec
  303.         #if sizeof(OSErr) > 4
  304.             #error "Result types larger than 4 bytes are not supported."
  305.         #endif
  306.     #endif
  307.     long    private_result;
  308.  
  309.     private_result = CallUniversalProc((UniversalProcPtr)NGetTrapAddress(0xAADB, 1),
  310.         kD0DispatchedPascalStackBased
  311.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  312.          | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
  313.          | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ourDevice))),
  314.         0x0000000D,
  315.         ourDevice);
  316.     return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
  317. }
  318.